package com.labi.designpattern.controller;

import com.labi.designpattern.service.HumanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HumanStrategyController {
    //===================================以下 是策略模式==========================================
    @Autowired
    private ApplicationContext applicationContext;

    /**
     * Strategy Pattern 策略模式来处理
     *
     * @return
     */
    @RequestMapping("/name2")
    public String getName(@RequestParam("type") String  type ) {
        HumanService humanService = applicationContext.getBean(type, HumanService.class);
        return  humanService.name();
    }
}
